<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>绑定 LDAP 目录</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ldap-bind" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ldap_bind</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">ldap_bind</span> &mdash; <span class="dc-title">绑定 LDAP 目录</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ldap-bind-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ldap_bind</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$bind_rdn</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$bind_password</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
  ]] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   使用指定的 RDN 和密码绑定到 LDAP 目录。 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ldap-bind-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">link_identifier</code></dt>

     <dd>

      <p class="para">
       通过 <span class="function"><a href="ldap_connect.html" class="function">ldap_connect()</a></span> 连接之后返回的 LDAP 连接标识。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">bind_rdn</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">bind_password</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
   </dl>

  </p>
  <p class="para">
   如果没有指定 <code class="parameter">bind_rdn</code> 和 <code class="parameter">bind_password</code> ，将会以匿名身份绑定。
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ldap-bind-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ldap-bind-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5386">
    <p><strong>Example #1 使用 LDAP Bind</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;using&nbsp;ldap&nbsp;bind<br /></span><span style="color: #0000BB">$ldaprdn&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'uname'</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;ldap&nbsp;rdn&nbsp;or&nbsp;dn<br /></span><span style="color: #0000BB">$ldappass&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'password'</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;associated&nbsp;password<br /><br />//&nbsp;connect&nbsp;to&nbsp;ldap&nbsp;server<br /></span><span style="color: #0000BB">$ldapconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"ldap.example.com"</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect&nbsp;to&nbsp;LDAP&nbsp;server."</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$ldapconn</span><span style="color: #007700">)&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;binding&nbsp;to&nbsp;ldap&nbsp;server<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ldapbind&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$ldapconn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ldaprdn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ldappass</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;verify&nbsp;binding<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$ldapbind</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"LDAP&nbsp;bind&nbsp;successful..."</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"LDAP&nbsp;bind&nbsp;failed..."</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="example-5387">
    <p><strong>Example #2 Using LDAP Bind Anonymously</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//using&nbsp;ldap&nbsp;bind&nbsp;anonymously<br /><br />//&nbsp;connect&nbsp;to&nbsp;ldap&nbsp;server<br /></span><span style="color: #0000BB">$ldapconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"ldap.example.com"</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect&nbsp;to&nbsp;LDAP&nbsp;server."</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$ldapconn</span><span style="color: #007700">)&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;binding&nbsp;anonymously<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ldapbind&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ldap_bind</span><span style="color: #007700">(</span><span style="color: #0000BB">$ldapconn</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$ldapbind</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"LDAP&nbsp;bind&nbsp;anonymous&nbsp;successful..."</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"LDAP&nbsp;bind&nbsp;anonymous&nbsp;failed..."</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ldap-bind-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="ldap_unbind.html" class="function" rel="rdfs-seeAlso">ldap_unbind()</a> - Unbind from LDAP directory</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>